<!--
 * @FilePath     : /study_code/vue2.x/transition-group2 copy.html
 * @Description  : 列表的交错过渡
 * @Date         : 2025-05-03 08:40:27
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-05-03 08:40:27
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <style>
      .list-complete-item {
        transition: all 1s;
        display: inline-block;
        margin-right: 10px;
      }

      .list-complete-enter,
    .list-complete-leave-to

    /* .list-complete-leave-active for below version 2.1.8 */ {
        opacity: 0;
        transform: translateY(30px);
      }

      .list-complete-leave-active {
        position: absolute;
      }
    </style>
  </head>
  <body>
    <div id="app" class="demo">
      <input v-model="query" />
      <transition-group
        name="staggered-fade"
        tag="ul"
        v-bind:css="false"
        v-on:before-enter="beforeEnter"
        v-on:enter="enter"
        v-on:leave="leave"
      >
        <li v-for="(item, index) in computedList" v-bind:key="item.msg" v-bind:data-index="index">
          {{ item.msg }}
        </li>
      </transition-group>
    </div>

    <script src="/vue/dist/vue.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.14.1/lodash.min.js"></script>
    <script src="./common.js"></script>
    <script>
      // 自定义组件
      const myComponent = {
        data: function () {
          return {}
        },
        props: [],
        template: ``,
        methods: {},
      }

      var app = new Vue({
        el: '#app',
        data: function () {
          return {
            query: '',
            list: [
              { msg: 'Bruce Lee' },
              { msg: 'Jackie Chan' },
              { msg: 'Chuck Norris' },
              { msg: 'Jet Li' },
              { msg: 'Kung Fury' },
            ],
          }
        },
        computed: {
          computedList: function () {
            var vm = this
            return this.list.filter(function (item) {
              return item.msg.toLowerCase().indexOf(vm.query.toLowerCase()) !== -1
            })
          },
        },
        methods: {
          // 过渡事件监听
          beforeEnter: function (el) {
            el.style.opacity = 0
            el.style.height = 0
          },
          enter: function (el, done) {
            var delay = el.dataset.index * 150
            setTimeout(function () {
              Velocity(el, { opacity: 1, height: '1.6em' }, { complete: done })
            }, delay)
          },
          leave: function (el, done) {
            var delay = el.dataset.index * 150
            setTimeout(function () {
              Velocity(el, { opacity: 0, height: 0 }, { complete: done })
            }, delay)
          },
        },
      })
    </script>
  </body>
</html>
